import {
  Component, OnInit, OnChanges, DoCheck, AfterContentInit, AfterContentChecked,
  AfterViewInit, AfterViewChecked, OnDestroy, SimpleChanges, Input
} from '@angular/core';
import {Http, Headers} from "@angular/http";
import {Observable} from "rxjs/Rx";

let logIndex:number = 1;

@Component({
  selector: 'app-component-life',
  templateUrl: './component-life.component.html',
  styleUrls: ['./component-life.component.scss']
})
export class ComponentLifeComponent implements OnInit,OnChanges,DoCheck,AfterContentInit,AfterContentChecked,AfterViewInit,AfterViewChecked,OnDestroy {

  @Input()
  name:string;

  dataSource:Observable<any>;
  data:Object;


  logIt(msg:string) {
    console.log(`#${logIndex++} ${msg}`);
  }

  constructor(private http:Http) {
    this.logIt("name在constructor中为:" + name)
    // let myHeaders = new Headers();
    // myHeaders.append("")
    //
    // this.dataSource = this.http.get('/login').map((res)=>res.json());
  }

  ngOnChanges(changes:SimpleChanges):void {
    let name = changes['name'].currentValue;
    this.logIt("name在ngOnChanges中为:" + name)
  }

  ngDoCheck():void {
    this.logIt("ngDoCheck")
  }

  ngAfterContentInit():void {
    this.logIt("ngAfterContentInit")
  }

  ngAfterContentChecked():void {
    this.logIt("ngAfterContentChecked")
  }

  ngAfterViewInit():void {
    this.logIt("ngAfterViewInit")
  }

  ngAfterViewChecked():void {
    this.logIt("ngAfterViewChecked")
  }

  ngOnDestroy():void {
    this.logIt("ngOnDestroy")
  }

  ngOnInit() {
    this.logIt("ngOnInit")
    // this.dataSource.subscribe(
    //   (data) => this.data = data
    // )
  }

}
